using System;
using System.Collections.Generic;
using System.Text;

namespace Madason.MetaModel.DAO
{
	public class JdbcInterface
	{
		public static string GetPreparedStatementSetter(Class type)
		{
			if (type.Stereotype == Stereotype.Entity)
			{
				foreach (Attribute attr in type.Attributes)
				{
					if (attr.Stereotype == Stereotype.PrimaryKey)
						return GetPreparedStatementSetter(attr.Type);
				}
			}
			
			string typeName = type.ExplicitName;
			if (typeName == "String") return "setString";
			if (typeName == "int") return "setInt";
			if (typeName == "boolean") return "setBoolean";
			if (typeName == "float") return "setFloat";
			if (typeName == "double") return "setDouble";
			if (typeName == "Date") return "setTimestamp";
			throw new ArgumentException("invalid Datatype " + typeName);
		}

		public static string GetResultsetGetter(Class type)
		{
			string typeName = type.ExplicitName;
			if (typeName == "String") return "getString";
			if (typeName == "int") return "getInt";
			if (typeName == "boolean") return "getBoolean";
			if (typeName == "float") return "getDouble";
			if (typeName == "double") return "getDouble";
			if (typeName == "Date") return "getTimestamp";
			if (type.Stereotype == Stereotype.Enum) return "getInt";
			return "?" + typeName + "?";
		}


		public static string GetSqlType(Class type)
		{
			string typeName = type.ExplicitName;
			if (typeName == "String") return "java.sql.Types.VARCHAR";
			if (typeName == "int") return "java.sql.Types.INTEGER";
			if (typeName == "boolean") return "java.sql.Types.BIT";
			if (typeName == "float") return "java.sql.Types.FLOAT";
			if (typeName == "double") return "java.sql.Types.DOUBLE";
			if (typeName == "Date") return "java.sql.Types.DATE";
			if (type.Stereotype == Stereotype.Enum) return "java.sql.Types.INTEGER";
			return "?" + typeName + "?";
		}

	}
}
